package org.demo;

import org.demo.util.HttpRequestUtil;
import org.demo.util.HttpResponseVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ElasticSearchDemo {
	private static String root="http://localhost:9200";
	private static String index="demo";
	final static Logger LOGGER = LoggerFactory.getLogger(Do4log2.class);

	public static void main(String[] args) {
//		add("demo","1","{\r\n" + 
//				"  \"title\": \"Java 8 Optional In Depth\",\r\n" + 
//				"  \"category\":\"Java\",\r\n" + 
//				"  \"published_date\":\"23-FEB-2017\",\r\n" + 
//				"  \"author\":\"Rambabu Posa\"\r\n" + 
//				"}");
		System.out.println(get("demo", "1"));
	}

	public static void add(String type,String id,String body) {
		String url=getUrl(type,id);
		HttpRequestUtil.doPost(url, body, r->{
			System.out.println(r.getResult());
		});
	}
	public static String get(String type,String id) {
		String url=getUrl(type,id);
		HttpResponseVO doGet = HttpRequestUtil.doGet(url);
		return doGet.getResult();
	}
	
	public static String getUrl(String type,String id) {
		String url=String.format("%s/%s/%s/%s", root,index,type,id);
		LOGGER.info("post {}",url);
		return url;
	}
	
	
}
